<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;

class User extends AdminController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        // 查询所有用户
        $alldata = Db::view(['qq_user_data'=>'ud'])
                ->view(['qq_user'=>'u'],['*'],'u.id = ud.uid','right')
                ->paginate(10);
//                ->select();
        $data = $alldata->items();
        $page = $alldata->render();
        unset($data['pwd']);
        unset($data['zf_password']);
//        dump($data);

        return view('index',['data'=>$data,'page'=>$page]);
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * @return \think\response\View
     */
    public function shiming()
    {
        // 查询所有用户
        $alldata = Db::view(['qq_user_data'=>'ud'])
            ->view(['qq_user'=>'u'],['*'],'u.id = ud.uid','right')
            ->where('smstatus',2)
            ->paginate(10);
//        ->select();
        $data = $alldata->items();
        $page = $alldata->render();
        unset($data['pwd']);
        unset($data['zf_password']);
//        dump($data);

        return view('shiming',['data'=>$data,'page'=>$page]);
    }

    /**
     * @return mixed
     */
    public function changeshiming()
    {
        $status = input('post.status');
        $id = input('post.id');

        if($status == 3){
            $arr['smstatus'] = 3;
        }elseif ($status == 1){
            $arr['smstatus'] = 1;
            $arr['name'] = null;
            $arr['idcard'] = null;
        }else{
            $data['msg'] = '非法请求';
            return $data;
        }

        $res = db('user_data')
            ->where('uid',$id)
            ->update($arr);


        if($res){
            if($arr['smstatus'] == 3){
                $data['status'] = 3;
                $data['msg'] = '已通过审核';
            }elseif($arr['smstatus'] == 1){
                $data['status'] = 1;
                $data['msg'] = '已驳回审核';
            }
        }else{
            $data['msg'] = '操作失败';
        }

        return $data;
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        // 通过tel查询指定用户 $id其实是tel
        $alldata = Db::view(['qq_user_data'=>'ud'])
            ->view(['qq_user'=>'u'],['*'],'u.id = ud.uid','right')
            ->where('u.tel','like','%'.$id.'%')
            ->paginate(10);
//                ->select();
        $data = $alldata->items();
        $page = $alldata->render();
        unset($data['pwd']);
        unset($data['zf_password']);
//        dump($data);

        return view('index',['data'=>$data,'page'=>$page]);
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update()
    {

    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }

    /**
     * @return mixed
     */
    public function changestatus()
    {
        $arr['status'] = input('post.status')==1?2:1;
        $id = input('post.id');
        $res = db('user')
            ->where('id',$id)
            ->update($arr);
        if(!$res){
            $arr['status'] = input('post.status');
        }
        return $arr;
    }
}
